package Day017_缓冲流_转换流_序列化流_打印流.ZuoYe;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileReader;
import java.io.FileWriter;
import java.util.ArrayList;

/**
 * @author zhangyan
 * @date 2020/5/9 19:48
 */
public class Test6 {
    public static void main(String[] args) throws Exception{

        //创建高效字符输入流对象,关联数据源文件路径
        BufferedReader br0 = new BufferedReader(new FileReader("Demo02\\ccc\\1.txt"));
        BufferedReader br1 = new BufferedReader(new FileReader("Demo02\\ccc\\2.txt"));
        BufferedReader br2 = new BufferedReader(new FileReader("Demo02\\ccc\\3.txt"));

        //定义数组,添加br1 br2 br3
        BufferedReader[] b = {br0,br1,br2};

        //创建高效字符输出流,关联目的地文件路径
        BufferedWriter bw = new BufferedWriter(new FileWriter("Demo02\\ccc\\古诗.txt"));

        //循环读取文件每行数据
        //定义集合存储数据
        ArrayList<String> list = new ArrayList<>();

        //定义变量 存储读到的每行数据
        String line;

        //循环嵌套,遍历3个输入流对象
        for (int i = 0; i < b.length; i++) {
            while ((line = b[i].readLine()) != null){
                list.add(line);
            }
            //关流
            b[i].close();
        }
        //遍历集合,写出数据
        for (String s : list) {
            bw.write(s);
            bw.newLine();
        }
        //关流
        bw.close();
    }
}
